package com.System.service.CommentImpl;

import com.System.Dao.CommentDao;
import com.System.pojo.DisSupport;
import com.System.pojo.Post;
import com.System.pojo.Support;
import com.System.service.Comment;
import com.System.untils.SqlSessionFactoryUtils;
import com.cloudHouse.session.SqlSession;
import com.cloudHouse.session.SqlSessionFactory;

import java.util.List;

public class CommentService implements Comment {
    SqlSessionFactory sqlSessionFactory= SqlSessionFactoryUtils.getSqlSessionFactory();
    @Override
    public List<com.System.pojo.Comment> selectAllComment(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);

        List<com.System.pojo.Comment> comments = mapper.selectAllComment(comment);
        sqlSession.close();
        return comments;
    }

    @Override
    public List<com.System.pojo.Comment> selectOutOfMyComment(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);

        List<com.System.pojo.Comment> comments = mapper.selectOutOfMyComment(comment);
        sqlSession.close();
        return comments;

    }

    @Override
    public void addComment(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.addComment(comment);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void supportComment(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.supportComment(comment);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void deleteSupport(Support support) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.deleteSupport(support);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void updateComment(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.updateComment(comment);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public com.System.pojo.Comment selectLikeNumbers(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        com.System.pojo.Comment temp = mapper.selectLikeNumbers(comment);
        sqlSession.close();
        return temp;
    }

    @Override
    public void addDisSupport(DisSupport disSupport) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.addDisSupport(disSupport);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void deleteDisFavor(DisSupport disSupport) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.deleteDisFavor(disSupport);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public DisSupport hasDisSupport(DisSupport disSupport) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        DisSupport result = mapper.hasDisSupport(disSupport);
        sqlSession.close();
        return result;
    }

    @Override
    public Support hasSupport(Support support) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        Support result = mapper.hasSupport(support);
        sqlSession.close();
        return result;
    }

    @Override
    public void updateLikeNumber(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.updateLikeNumber(comment);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void addSupport(Support support) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.addSupport(support);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public void deleteMyComment(com.System.pojo.Comment comment) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        mapper.deleteMyComment(comment);
        sqlSession.commit();
        sqlSession.close();
    }

    @Override
    public Post selectPostOwner(Post post) {
        SqlSession sqlSession = sqlSessionFactory.openSession();
        CommentDao mapper = sqlSession.getMapper(CommentDao.class);
        Post result = mapper.selectPostOwner(post);
        sqlSession.close();
        return result;
    }
}
